
import Vue from 'vue'
import Vuex from 'vuex'
import createPersistedState from 'vuex-persistedstate'

Vue.use(Vuex)
export default new Vuex.Store({
  plugins: [createPersistedState()],
  state:{
      car:[],
     
  },
  mutations: {
     add(state,res) {
       for(let i=0; i<state.car.length;i++){
          if(res.id===state.car[i].id){
            state.car[i].cou+=res.cou 
           return
          }
       }
       state.car.push(res)
     },  
     addcar(state,res){
      for(let i=0; i<state.car.length;i++){
        if(res.id===state.car[i].id){
          state.car[i].cou=res.cou
         return
        }
     }
     state.car.push(res)
     },
     delete(state,id){
     let index=  state.car.findIndex(item=>item.id===id)
      state.car.splice(index,1)

     }
    
     
    

     


  },
  actions: {
  },
  getters:{


  

  }
})

